package com.ruoyi.count.service.impl;

import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.ruoyi.count.domain.StudentStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.count.mapper.StudentstandardscoresMapper;
import com.ruoyi.count.domain.Studentstandardscores;
import com.ruoyi.count.service.IStudentstandardscoresService;

/**
 * studentstandardscoresService业务层处理
 * 
 * @author yxy
 * @date 2024-10-24
 */
@Service
public class StudentstandardscoresServiceImpl implements IStudentstandardscoresService 
{
    @Autowired
    private StudentstandardscoresMapper studentstandardscoresMapper;

    /**
     * 查询studentstandardscores
     * 
     * @param id studentstandardscores主键
     * @return studentstandardscores
     */
    @Override
    public Studentstandardscores selectStudentstandardscoresById(Long id)
    {
        return studentstandardscoresMapper.selectStudentstandardscoresById(id);
    }

    /**
     * 查询studentstandardscores列表
     * 
     * @param studentstandardscores studentstandardscores
     * @return studentstandardscores
     */
    @Override
    public List<Studentstandardscores> selectStudentstandardscoresList(Studentstandardscores studentstandardscores)
    {
        return studentstandardscoresMapper.selectStudentstandardscoresList(studentstandardscores);
    }

    /**
     * 新增studentstandardscores
     * 
     * @param studentstandardscores studentstandardscores
     * @return 结果
     */
    @Override
    public int insertStudentstandardscores(Studentstandardscores studentstandardscores)
    {
        return studentstandardscoresMapper.insertStudentstandardscores(studentstandardscores);
    }

    /**
     * 修改studentstandardscores
     * 
     * @param studentstandardscores studentstandardscores
     * @return 结果
     */
    @Override
    public int updateStudentstandardscores(Studentstandardscores studentstandardscores)
    {
        return studentstandardscoresMapper.updateStudentstandardscores(studentstandardscores);
    }

    /**
     * 批量删除studentstandardscores
     * 
     * @param ids 需要删除的studentstandardscores主键
     * @return 结果
     */
    @Override
    public int deleteStudentstandardscoresByIds(Long[] ids)
    {
        return studentstandardscoresMapper.deleteStudentstandardscoresByIds(ids);
    }

    /**
     * 删除studentstandardscores信息
     * 
     * @param id studentstandardscores主键
     * @return 结果
     */
    @Override
    public int deleteStudentstandardscoresById(Long id)
    {
        return studentstandardscoresMapper.deleteStudentstandardscoresById(id);
    }

    /**
     * 获取已经计算过分数时间  时间格式 : 2024-11
     * @param grade 年级
     * @param schoolId 学校id
     * @return
     */
    @Override
    public String getCalculationTime(String grade, String schoolId) {
        // 拿到查询出来的以及生成的成绩的列表 ,将时间单独提出出来
        Set<Date> dates = studentstandardscoresMapper.getCalculationTime(grade,schoolId).stream().map(Studentstandardscores::getCalculationtime).collect(Collectors.toSet());
        // 转化为需要的时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        // 转化为["2024-07", "xxxx-xx", "xxxx-xx"]字符串返回
        return dates.stream()
                .map(date -> LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault()))
                .map(formatter::format)
                .collect(Collectors.joining(", "));
    }

    /**
     * 根据学生id查询学生成绩
     * @param studentid
     * @return
     */
    @Override
    public List<Studentstandardscores> selectStudentstandardscoresListbyStudentid(String studentid) {
        return studentstandardscoresMapper.selectStudentstandardscoresListbyStudentid(studentid);
    }
}
